import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.ArrayList;

public class ServerApp {
    private static BaseDataStorage dataStorage = new Storage();
    private static Journal journal = new Journal("log.txt");
    private static ArrayList<ServerDescriptor> slaveList = new ArrayList<ServerDescriptor>();
    private static boolean Mode;

    public static void main(String[] args) {
        try {
            // creating sync thread
            new SyncThread(journal, slaveList).start();

            ServerSocket socket = new ServerSocket(0, 0, InetAddress.getByName("localhost"));
            System.out.println("_= Server =_ \n address:");
            System.out.println(socket.getInetAddress().getHostAddress() + " " + socket.getLocalPort());
            while(true)
                new Server(socket.accept(), dataStorage, journal, slaveList);

        } catch (IOException e) {
            System.out.print("Error of working server!");
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("Error! " + e.getMessage());
        }
    }
}